/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

/* Device header file */
#include <xc.h>
#include <p33FJ128MC802.h>

#include <stdint.h>        /* Includes uint16_t definition                    */
#include <stdbool.h>       /* Includes true/false definition */

#include "dsp_device.h"

register int accu_A asm("A");
register int accu_B asm("B");

void dsp_clear(int accu)
{
    if(accu==0)
    {
        accu_A = __builtin_clr();
    }
    else accu_B = __builtin_clr();
}

void dsp_mac(int accu, int a, int b)
{
    int *xmemory;
    int *ymemory;
    int xVal, yVal;

    if(accu=0)
    {
        accu_A = __builtin_mpy(a, b,
                &xmemory, &xVal, 0,
                &ymemory, &yVal, 0);
    }
    else
    {
        accu_B = __builtin_mpy(a, b,
                &xmemory, &xVal, 0,
                &ymemory, &yVal, 0);
    }
}

void dsp_subab(int accu)
{
    if(accu=0)
    {
        accu_A = __builtin_subab(accu_A, accu_B);
    }
    else
    {
        accu_B = __builtin_subab(accu_A, accu_B);
    }
}

void dsp_sftac(int accu, int i)
{
    if(accu=0)
    {
        accu_A = __builtin_sftac(accu_A, i);
    }
    else
    {
        accu_B = __builtin_sftac(accu_B, i);
    }
}

void dsp_addab(int accu)
{
    if(accu=0)
    {
        accu_A = __builtin_addab(accu_A, accu_B);
    }
    else
    {
        accu_B = __builtin_addab(accu_A, accu_B);
    }
}

void dsp_add(int accu, int i)
{
    if(accu=0)
    {
        accu_A = __builtin_add(accu_A, i);
    }
    else
    {
        accu_B = __builtin_add(accu_B, i);
    }
}